package offer;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class offer61 {
    public static boolean isStraight(int[] nums) {
        Set<Integer> set = new HashSet<>();
        int max=0,min=0;
        for (int i = 0; i < nums.length ; i++) {
            if(nums[i]==0)continue;
            max = Math.max(nums[i],max);
            min = Math.min(nums[i],min);
            if(set.contains(nums[i])) return false;
            else
                set.add(nums[i]);
        }
       return max-min<=5;
    }
    public static boolean isStraight2(int[] nums) {
        int count=0;
        Arrays.sort(nums);
        for (int i = 0; i <nums.length-1; i++) {
            if(nums[i]==0) {count++;continue;}
            if(nums[i]==nums[i+1]) return false;
            else if(nums[i+1]!=nums[i]+1)
            {
                count = count-(nums[i+1]-nums[i]-1);
            }
        }
        if(count>=0) return true;
       return false;
    }

    public static void main(String[] args) {
        int []nums = {1,2,0,0,5};
        isStraight2(nums);
    }
}
